package com.tarena.vehicle.management.controller;

import com.tarena.vehicle.common.pojo.vo.PageData;
import com.tarena.vehicle.common.web.JsonResult;
import com.tarena.vehicle.management.pojo.param.VehicleAddNewParam;
import com.tarena.vehicle.management.pojo.param.VehicleUpdateParam;
import com.tarena.vehicle.management.pojo.query.VehicleQuery;
import com.tarena.vehicle.management.pojo.vo.VehicleListItemVO;
import com.tarena.vehicle.management.service.IVehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/vehicle")
@Api(tags = "车辆基本信息管理")
public class VehicleController {

    private static final Logger logger= LoggerFactory.getLogger(VehicleController.class);

    @Autowired
    private IVehicleService vehicleService;

    @GetMapping("/get-all")
    @ApiOperation("获取所有车辆信息,可传参进行条件查询以及分页查询")
    public JsonResult<PageData<VehicleListItemVO>> getAll(VehicleQuery vehicleQuery,Integer pageNum,Integer pageSize){
        PageData<VehicleListItemVO> pageData=vehicleService.getAll(vehicleQuery,pageNum,pageSize);
        return JsonResult.ok(pageData);
    }

    @ApiOperation("新增车辆信息")
    @PostMapping("/add-new")
    public JsonResult addNew(@Validated VehicleAddNewParam vehicleAddNewParam){
        logger.info("接收到的车辆信息{}",vehicleAddNewParam);
        vehicleService.addNew(vehicleAddNewParam);
        return JsonResult.ok("添加成功");
    }

    @PostMapping("/delete")
    @ApiOperation("删除车辆信息")
    public JsonResult deleteByIds(Integer id){
        logger.info("接收到所要删除的车辆信息ID为:{}",id);
        vehicleService.deleteById(id);
        return JsonResult.ok("删除成功");
    }

    @PostMapping("/update")
    @ApiOperation("修改车辆信息,包含各类状态修改")
    public JsonResult update(VehicleUpdateParam vehicleUpdateParam){
        logger.info("接收到所要修改车辆信息为:{}",vehicleUpdateParam);
        vehicleService.update(vehicleUpdateParam);
        return JsonResult.ok("修改成功");
    }

}
